import { memo } from "react";
import StudentStyle from "./style";
import type { StudentType } from "../../../../graphql/student";
import { Image } from "antd";

const StudentCard = memo((
  props: {
    data: StudentType,
    setStudentData: (data: StudentType) => void,
    setDrawerOpen: (open: boolean) => void
  }
) => {
  const { data, setStudentData, setDrawerOpen } = props;
  const studentClick = (data: StudentType) => {
    setStudentData(data);
    setDrawerOpen(true);
  };
  return (
    <StudentStyle>
      <Image
        src={
          data.avatar ?? "https://danyun.oss-cn-chengdu.aliyuncs.com/brand.png"
        }
        height={140}
        alt={"头像加载错误"}
      />
      <div className="name" onClick={() => studentClick(data)}>
        {data.name.length === 0 ? `淡云教育用户${data.id}` : data.name}
      </div>
    </StudentStyle>
  );
});

export default StudentCard;
